package com.thinta.wind.ui.home.fragment

import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.lifecycle.ViewModelProvider
import com.thinta.wind.R
import com.thinta.wind.base.BaseFragment
import com.thinta.wind.base.BaseModel
import com.thinta.wind.base.ViewModelFactory
import com.thinta.wind.databinding.HomeFragmentBinding
import com.thinta.wind.ui.home.HomePageAdapter
import kotlinx.android.synthetic.main.home_fragment.*

class HomeFragment : BaseFragment<BaseModel, HomeFragmentBinding>() {

    private val tabList = listOf("关注", "热门")

    private val tabFragment = listOf(FollowFragment(), HotFragment())

    companion object {
        fun newInstance() = HomeFragment()
    }


    override fun afterCreate() {
        setTab()
    }

    private fun setTab(){
        dataBinding?.homePager?.adapter = HomePageAdapter(tabFragment, tabList, parentFragmentManager, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)
        dataBinding?.tabLayout?.setupWithViewPager(home_pager)
    }

    override fun getModelFactory(): ViewModelProvider.NewInstanceFactory = ViewModelFactory()

    override fun viewModelClass(): Class<BaseModel> = BaseModel::class.java

    override fun getLayoutId(): Int = R.layout.home_fragment

}
